package com.rfid.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.rfid.domain.VO.RecordVO;
import com.rfid.mapper.RfidProductMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rfid.mapper.RfidRecordMapper;
import com.rfid.domain.RfidRecord;
import com.rfid.service.IRfidRecordService;

/**
 * 仓库物品流动记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-29
 */
@Service
public class RfidRecordServiceImpl implements IRfidRecordService 
{
    @Autowired
    private RfidRecordMapper rfidRecordMapper;

    @Autowired
    private SysUserMapper userMapper;
    @Autowired
    private RfidProductMapper rfidProductMapper;
    /**
     * 查询仓库物品流动记录
     * 
     * @param id 仓库物品流动记录主键
     * @return 仓库物品流动记录
     */
    @Override
    public RfidRecord selectRfidRecordById(Long id)
    {
        return rfidRecordMapper.selectRfidRecordById(id);
    }

    /**
     * 查询仓库物品流动记录列表
     * 
     * @param rfidRecord 仓库物品流动记录
     * @return 仓库物品流动记录
     */
    @Override
    public List<RecordVO> selectRfidRecordList(RfidRecord rfidRecord)
    {
        List<RfidRecord> rfidRecords = rfidRecordMapper.selectRfidRecordList(rfidRecord);
        List<RecordVO> recordVOS=new ArrayList<>();
        for (RfidRecord rfidRecord1:rfidRecords){
            String nickName = userMapper.selectUserById(rfidRecord1.getUpdataBy()).getNickName();
            String name = rfidProductMapper.selectRfidProductById(rfidRecord1.getProduct()).getName();
            RecordVO recordVO=new RecordVO(rfidRecord1,name,nickName);
            recordVOS.add(recordVO);
        }
        return recordVOS;
    }

    /**
     * 新增仓库物品流动记录
     * 
     * @param rfidRecord 仓库物品流动记录
     * @return 结果
     */
    @Override
    public int insertRfidRecord(RfidRecord rfidRecord)
    {
        return rfidRecordMapper.insertRfidRecord(rfidRecord);
    }

    /**
     * 修改仓库物品流动记录
     * 
     * @param rfidRecord 仓库物品流动记录
     * @return 结果
     */
    @Override
    public int updateRfidRecord(RfidRecord rfidRecord)
    {
        return rfidRecordMapper.updateRfidRecord(rfidRecord);
    }

    /**
     * 批量删除仓库物品流动记录
     * 
     * @param ids 需要删除的仓库物品流动记录主键
     * @return 结果
     */
    @Override
    public int deleteRfidRecordByIds(Long[] ids)
    {
        return rfidRecordMapper.deleteRfidRecordByIds(ids);
    }

    /**
     * 删除仓库物品流动记录信息
     * 
     * @param id 仓库物品流动记录主键
     * @return 结果
     */
    @Override
    public int deleteRfidRecordById(Long id)
    {
        return rfidRecordMapper.deleteRfidRecordById(id);
    }
}
